package leetcode.code1481;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {
	public int findLeastNumOfUniqueInts(int[] arr, int k) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int num : arr) {
			map.put(num, map.getOrDefault(num, 0) + 1);
		}
		List<Integer> list = new ArrayList<>();
		for (int num : map.values()) {
			list.add(num);
		}
		Collections.sort(list);
		int p = 0;
		while (k > 0 && p < list.size()) {
			k -= list.get(p);
			if (k >= 0) {
				p++;
			}
		}
		return list.size() - p;
	}

	public Map<Integer, Integer> counter(int[] array) {
		Map<Integer, Integer> cnter = new HashMap<>();
		for (int num : array) {
			cnter.put(num, cnter.getOrDefault(num, 0) + 1);
		}
		return cnter;
	}
	
}
